package models

import (
	"blog_api/db"
)

const TOKEN_VALID_TIME = 86400

type Admin struct {
	Id         int    `gorm:"column(id)" json:"id"`
	Name       string `gorm:"column(name)" json:"name"`
	Username   string `gorm:"column(username)" json:"username"`
	Password   string `gorm:"column(password)" json:"password"`
	Salt       string `gorm:"column(salt)" json:"salt"`
	RoleId     int    `gorm:"column(role_id)" json:"role_id"`
	Email      string `gorm:"column(email)" json:"email"`
	AddTime    uint64 `gorm:"column(add_time)" json:"add_time"`
	UpdateTime uint64 `gorm:"column(update_time)" json:"update_time"`
}

func (*Admin) TableName() string {
	return "blog_admin"
}

/**
 * AdminUserInfo
 * @Description: 后台登录用户信息
 * @Author: Jazk-Z
 * @param where
 * @return Admin
 * @return int64
 */
func AdminUserInfo(where string) (Admin, error) {
	var a Admin
	sel := db.Mysql.Model(&Admin{}).Where(where).Find(&a).Error
	if sel != nil {
		return a, sel
	}
	return a, nil
}

func AdminUserUpdate(data interface{}, where string) error {
	upd := db.Mysql.Model(&Admin{}).Where(where).Updates(data)
	return upd.Error
}
